VERSION 5.00
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "msdatgrd.ocx"
Object = "{B3FB64BF-91F9-11D7-A482-0008A14158BC}#2.22#0"; "ITGControls.ocx"
Begin VB.Form frmITGPicker 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Picker List"
   ClientHeight    =   3945
   ClientLeft      =   -105
   ClientTop       =   -120
   ClientWidth     =   7425
   ControlBox      =   0   'False
   BeginProperty Font 
      Name            =   "Tahoma"
      Size            =   8.25
      Charset         =   0
      Weight          =   700
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Icon            =   "frmITGPicker.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   3945
   ScaleWidth      =   7425
   StartUpPosition =   2  'CenterScreen
   Begin VB.Frame fraSearch 
      Caption         =   "Primary Search Column"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   1905
      TabIndex        =   3
      Top             =   3375
      Width           =   2670
      Begin VB.OptionButton optCode 
         Caption         =   "ID/Code"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   180
         TabIndex        =   5
         Top             =   180
         Width           =   915
      End
      Begin VB.OptionButton optName 
         Caption         =   "Name/Desc"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   1320
         TabIndex        =   4
         Top             =   180
         Width           =   1230
      End
   End
   Begin VB.TextBox txtFind 
      Appearance      =   0  'Flat
      Enabled         =   0   'False
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   285
      Left            =   45
      Locked          =   -1  'True
      TabIndex        =   2
      Top             =   3000
      Width           =   4515
   End
   Begin ITGControls.ITGCommandButton cmdCancel 
      Height          =   345
      Left            =   6120
      TabIndex        =   1
      Top             =   3525
      Width           =   1230
      _ExtentX        =   2170
      _ExtentY        =   609
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Caption         =   "&Cancel"
   End
   Begin ITGControls.ITGCommandButton cmdOK 
      Height          =   345
      Left            =   4860
      TabIndex        =   0
      Top             =   3525
      Width           =   1230
      _ExtentX        =   2170
      _ExtentY        =   609
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Caption         =   "&OK"
   End
   Begin MSDataGridLib.DataGrid dtgList 
      Height          =   2880
      Left            =   0
      TabIndex        =   6
      Top             =   60
      Width           =   7395
      _ExtentX        =   13044
      _ExtentY        =   5080
      _Version        =   393216
      AllowUpdate     =   0   'False
      AllowArrows     =   -1  'True
      Appearance      =   0
      HeadLines       =   1
      RowHeight       =   15
      TabAction       =   2
      FormatLocked    =   -1  'True
      AllowDelete     =   -1  'True
      BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ColumnCount     =   2
      BeginProperty Column00 
         DataField       =   ""
         Caption         =   ""
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   1033
            SubFormatType   =   0
         EndProperty
      EndProperty
      BeginProperty Column01 
         DataField       =   ""
         Caption         =   ""
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   1033
            SubFormatType   =   0
         EndProperty
      EndProperty
      SplitCount      =   1
      BeginProperty Split0 
         AllowRowSizing  =   0   'False
         BeginProperty Column00 
            ColumnAllowSizing=   -1  'True
            Locked          =   -1  'True
            ColumnWidth     =   1695.118
         EndProperty
         BeginProperty Column01 
            Locked          =   -1  'True
            ColumnWidth     =   4064.882
         EndProperty
      EndProperty
   End
End
Attribute VB_Name = "frmITGPicker"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Option Explicit

Enum ePickType
    QClientEmployee = 101
    QClientSupplier = 102
    QSecDepartment = 103
    QTripTicket = 104
    QPETTYCASHAD = 105
    QTRUCKER = 106
    QTruckerRoute = 107
    QTradeShow = 108
    QDistributor = 109
    QAccounts = 110
    QSupplier = 111
    QSupplierNT = 112
    QSupply = 113
    QProduct = 114
    QPriceMatrix = 115
    QEmployee = 116
    QEmployeeDriver = 117
    QOCustomer = 118
    QBank = 119
    QLocation = 120
    QFixedAssetVehicle = 121
    QFixedAsset = 122
    QFixedAssetVessel = 123
    QFixedAssetEquipment = 124
    QFixedAssetOthers = 125
    QLocationCity = 126
    QLocationProv = 127
    QLocationArea = 128
    QMarketSegment = 129
    QProductDivision = 130
    QProfitCenter = 131
    QWarehouse = 132
    QCustomerExp = 133
    QCustomer = 134
    QSalesman = 135
    QGroupings = 136
    QBarcode = 137
    QPayables = 138
    QProductWPartNo = 140
    QComponents = 141
    QWork = 148
    
    ' code for PMS EXPENSE

    Qclientsupplierall = 143
    Qsupplierall = 144
    Qemployeesupplierall = 145
    
    QUserRole = 146
    QProject = 147
    
End Enum

Public zType As ePickType
Public zCode As String
Public zName As String
Public zPart As String
Public sColumnVariable As String
Public Condition As String

Private rsPickList As ADODB.Recordset

Private connList As ADODB.Connection

Private Sub cmdCancel_Click()
    Unload Me
    Set frmITGPicker = Nothing
End Sub

Private Sub cmdOK_Click()
On Error GoTo ErrHandler

    SelectOK
    
ErrHandler:
    If err.Number <> 0 Then
        MsgBox err.Description, vbCritical, "Error"
        Unload Me
    End If
    
End Sub

Private Sub dtgList_DblClick()
    If rsPickList.RecordCount <> 0 Then SelectOK
End Sub

Private Sub dtgList_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyEscape Then
        Unload Me
        Set frmITGPicker = Nothing
    ElseIf KeyAscii = 8 Then
        If txtFind.Text <> "" Then
            txtFind = Mid(txtFind.Text, 1, Len(txtFind.Text) - 1)
            If txtFind <> "" Then
                FilterString True
            Else
                FilterString False
            End If
        End If
    ElseIf KeyAscii = 13 Then
        SelectOK
    ElseIf KeyAscii = 39 Then
        KeyAscii = 0
    Else
        txtFind = txtFind.Text + UCase(Chr(KeyAscii))
        FilterString True
        dtgList.SetFocus
    End If
End Sub


Private Sub Form_Activate()
    If zType = QAccounts Then
        optCode.Value = True
    Else
        optName.Value = True
    End If
    
End Sub

Private Sub Form_Load()
On Error GoTo TheSource

    If Not lModal Then FormWaitShow App.Path & "\Transmit.avi", "Loading list . . ."
    
    If GetValueFrTable("lBit", "SYSTEM_OPTION", "cCode = 'ITM_MAN_USEPARTNO'") = True Then
        If Me.zType = QProduct Then
            Me.zType = QProductWPartNo
            dtgList.Columns.Add 2
            dtgList.Columns(2).Width = 1500
            dtgList.Width = dtgList.Width + 1500
            Me.Width = Me.Width + 1500
            dtgList.Columns(2).DataField = "foriegnid"
            dtgList.Columns(2).Caption = GetValueFrTable("cValue", "SYSTEM_OPTION", "cCode = 'ITM_MAN_BARCODE'")
        End If
    End If
    

    lPickListActive = True
    Call LoadScript
    txtFind.Text = sFilterString
    
    FormWaitHide
    
TheSource:
    If err.Number = 3709 Then
        Set connList = Nothing
        FormWaitHide
        Unload Me
    End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set rs = Nothing
    Set rsPickList = Nothing
    Set connList = Nothing
    sFilterString = Empty
    lPickListActive = False
End Sub

Private Sub SelectOK()

    zCode = ""
    zName = ""
    zPart = ""
    
    If rsPickList.RecordCount = 0 Then Exit Sub
    
    If zType = QAccounts Then
        If GetValueFrTable("cType", "ACCOUNT", "cAcctNo = '" & rsPickList!ID & "'") = "General" Then
            If MsgBox("'General Account' has been selected. Do you want to continue?", vbYesNo + vbInformation, "Comunion") = vbYes Then
                zCode = rsPickList!ID
                zName = rsPickList!Description
            Else
                zCode = ""
                zName = ""
            End If
        Else
            zCode = rsPickList!ID
            zName = rsPickList!Description
        End If
    Else
        zCode = rsPickList!ID
        zName = rsPickList!Description
        If dtgList.Columns.Count = 3 Then zPart = rsPickList!ForiegnID
    End If
    
    
    Unload Me
End Sub

Private Sub FilterString(lReset As Boolean)
'On Error Resume Next
    With rsPickList
        If sColumnVariable = "Code" Then
            If lReset And Trim(txtFind) <> "" Then
                .Filter = "id like '%" & Trim(txtFind.Text) & "%'"
            Else
                .Filter = "id <> ''"
            End If
        Else
            If lReset And Trim(txtFind) <> "" Then
                .Filter = "description like '%" & Trim(txtFind.Text) & "%'"
            Else
                .Filter = "description <> ''"
            End If
        End If
    End With
End Sub

Public Sub ShowForm()
If rs.RecordCount = 0 Then Exit Sub
    If zType <> QUserRole And zType <> Qclientsupplierall And zType <> Qsupplierall And zType <> Qemployeesupplierall Then
            frmITGPicker.Caption = rs!cTitle
            If sColumnVariable = "Code" Then
                dtgList.Columns(0).DataField = "id"
                dtgList.Columns(1).DataField = "description"
        
                dtgList.Columns(0).Width = 1500
                dtgList.Columns(1).Width = 5300
        
               dtgList.Columns(0).Caption = rs!cCodeTitle
                dtgList.Columns(1).Caption = rs!cDescTitle
        
            Else
                dtgList.Columns(0).DataField = "description"
                dtgList.Columns(1).DataField = "id"
        
                dtgList.Columns(0).Width = 5300
                dtgList.Columns(1).Width = 1500
        
                dtgList.Columns(0).Caption = rs!cDescTitle
                dtgList.Columns(1).Caption = rs!cCodeTitle
        
            End If
    Else
        If zType = Qclientsupplierall Then
            frmITGPicker.Caption = "Client & Supplier"
        ElseIf zType = Qsupplierall Then
            frmITGPicker.Caption = "Supplier Trade & Non-Trade"
        ElseIf zType = Qemployeesupplierall Then
            frmITGPicker.Caption = "Supplier Trade & Non-Trade & Employee"
        ElseIf zType = QUserRole Then
            frmITGPicker.Caption = "User Role"
        End If
        dtgList.Columns(0).DataField = "description"
        dtgList.Columns(1).DataField = "id"

        dtgList.Columns(0).Width = 5300
        dtgList.Columns(1).Width = 1500

        dtgList.Columns(0).Caption = "Name"
        dtgList.Columns(1).Caption = "Code"
    End If


    Set dtgList.DataSource = rsPickList
    dtgList.Refresh

    If Not lModal Then FormWaitHide
    lModal = False
    FilterString True

End Sub

Private Sub optCode_Click()
    sColumnVariable = "Code"
    ShowForm
    dtgList.SetFocus
End Sub

Private Sub optName_Click()
    sColumnVariable = "Desc"
    ShowForm
    dtgList.SetFocus
End Sub

Private Sub LoadScript()

    OpenNewConnection connList
    
    If zType = Qclientsupplierall Then
            sSQL = "EXEC rsp_client_supplier '" & COID & "'"
    ElseIf zType = Qsupplierall Then
            sSQL = "EXEC rsp_supplier '" & COID & "'"
    ElseIf zType = Qemployeesupplierall Then
            sSQL = "EXEC rsp_employee_supplier '" & COID & "'"
    ElseIf zType = QUserRole Then
            sSQL = "select [Description] ,RoleID as ID from sec_role" 'where cCompID = '" & COID & "'"
    Else
        sSQL = "select * from system_picker where cCode = '" & zType & "'"
    End If
    Set rs = Nothing
    Set rs = New ADODB.Recordset
    'sSQL = "select * from system_picker where cCode = '" & zType & "'"
    rs.Open sSQL, connList, adOpenKeyset, adLockReadOnly
     
    If zType <> QUserRole And zType <> Qclientsupplierall And zType <> Qsupplierall And zType <> Qemployeesupplierall Then
    sSQL = rs!cScript & " " & Condition
    End If
    
    Set rsPickList = Nothing
    Set rsPickList = New ADODB.Recordset
    rsPickList.Open sSQL, connList, adOpenStatic, adLockBatchOptimistic
End Sub


